// Utilities for writing and reading from the EEPROM

float readInt(int address) {
  union intStore {
    byte intByte[2];
    int intVal;
  } intOut;
  
  for (int i = 0; i < 2; i++) 
    intOut.intByte[i] = EEPROM.read(address + i);
  return intOut.intVal;
}

void writeInt(int value, int address) {
  union intStore {
    byte intByte[2];
    int intVal;
  } intIn;
  
  intIn.intVal = value;
  for (int i = 0; i < 2; i++) 
    EEPROM.write(address + i, intIn.intByte[i]);
}

float readFloat(int address) {
  union floatStore {
    byte floatByte[4];
    float floatVal;
  } floatOut;
  
  for (int i = 0; i < 4; i++) 
    floatOut.floatByte[i] = EEPROM.read(address + i);
  return floatOut.floatVal;
}

void writeFloat(float value, int address) {
  union floatStore {
    byte floatByte[4];
    float floatVal;
  } floatIn;
  
  floatIn.floatVal = value;
  for (int i = 0; i < 4; i++) 
    EEPROM.write(address + i, floatIn.floatByte[i]);
}
